//
//  HYSelectInviterCell.m
//  Booking
//
//  Created by Duntech on 2018/4/25.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYSelectInviterCell.h"

@implementation HYSelectInviterCellModel

@end

@interface HYSelectInviterCell ()

@property (nonatomic,strong) YYLabel *emailLabel;
@property (nonatomic,strong) UIView *line;

@end

@implementation HYSelectInviterCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.selectBtn];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.emailLabel];
        [self.contentView addSubview:self.line];
    }
    return self;
}

- (void)layoutSubviews{
    
    [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10 * WIDTH_MULTIPLE);
        make.top.bottom.equalTo(self);
        make.height.equalTo(self.selectBtn.mas_width);
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.selectBtn.mas_right).offset(10 * WIDTH_MULTIPLE);
    }];
    
    [_emailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.nameLabel.mas_right).offset(20 * WIDTH_MULTIPLE).priorityHigh();
        make.right.equalTo(self).offset(-20 * WIDTH_MULTIPLE).priorityHigh;

    }];
    
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.right.equalTo(self).offset(-10);
        make.bottom.equalTo(self);
        make.height.mas_equalTo(1);
    }];
}

- (void)configWithModel:(id)model{
    
    HYSelectInviterCellModel *cellModel = (HYSelectInviterCellModel *)model;
    self.selectBtn.selected = cellModel.isSelected;
    self.nameLabel.text = cellModel.realName;
    self.emailLabel.text = [NSString stringWithFormat:@"(%@)",cellModel.email];
}

#pragma mark - lazyload
- (UIButton *)selectBtn{
    
    if (!_selectBtn) {
        _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_selectBtn setImage:[UIImage imageNamed:@"select"] forState:UIControlStateSelected];
        [_selectBtn setImage:[UIImage imageNamed:@"not_select"] forState:UIControlStateNormal];
        _selectBtn.userInteractionEnabled = NO;
    }
    return _selectBtn;
}

- (YYLabel *)nameLabel{
    
    if (!_nameLabel) {
        _nameLabel = [YYLabel new];
        _nameLabel.textColor = KAPP_BLACK_COLOR;
        _nameLabel.font = KFitFont(16);
        [_nameLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    }
    return _nameLabel;
}

- (YYLabel *)emailLabel{
    
    if (!_emailLabel) {
        _emailLabel = [YYLabel new];
        _emailLabel.textColor = KCOLOR(@"4bb9ca");
        _emailLabel.font = KFitFont(16);
        _emailLabel.numberOfLines = 0;
        _emailLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _emailLabel;
}

- (UIView *)line{
    
    if (!_line) {
        _line = [UIView new];
        _line.backgroundColor = KAPP_SEPERATOR_COLOR;
    }
    return _line;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
